Quals & Field & Type & Description \\
\hline
$\mathit{RO}_\mathit{run}$ & {\tt uuid} & string & unique identifier/object reference \\
-$\mathit{RO}_\mathit{ins}$ & {\tt host} & host ref & the host the CPU is in \\
-$\mathit{RO}_\mathit{ins}$ & {\tt number} & int & the number of the physical CPU within the host \\
-$\mathit{RO}_\mathit{ins}$ & {\tt vendor} & string & the vendor of the physical CPU \\
-$\mathit{RO}_\mathit{ins}$ & {\tt speed} & int & the speed of the physical CPU \\
-$\mathit{RO}_\mathit{ins}$ & {\tt modelname} & string & the model name of the physical CPU \\
+$\mathit{RO}_\mathit{run}$ & {\tt host} & host ref & the host the CPU is in \\
+$\mathit{RO}_\mathit{run}$ & {\tt number} & int & the number of the physical CPU within the host \\
+$\mathit{RO}_\mathit{run}$ & {\tt vendor} & string & the vendor of the physical CPU \\
+$\mathit{RO}_\mathit{run}$ & {\tt speed} & int & the speed of the physical CPU \\
+$\mathit{RO}_\mathit{run}$ & {\tt modelname} & string & the model name of the physical CPU \\
+$\mathit{RO}_\mathit{run}$ & {\tt stepping} & string & the stepping of the physical CPU \\
+$\mathit{RO}_\mathit{run}$ & {\tt flags} & string & the flags of the physical CPU \\
$\mathit{RO}_\mathit{run}$ & {\tt utilisation} & float & the current CPU utilisation \\
\hline
\end{longtable}
\vspace{0.3cm}
\vspace{0.3cm}
\vspace{0.3cm}
-\subsubsection{RPC name:~get\_utilisation}
+\subsubsection{RPC name:~get\_stepping}
{\bf Overview:}
-Get the utilisation field of the given host\_cpu.
+Get the stepping field of the given host\_cpu.
\noindent {\bf Signature:}
-\begin{verbatim} float get_utilisation (session_id s, host_cpu ref self)\end{verbatim}
+\begin{verbatim} string get_stepping (session_id s, host_cpu ref self)\end{verbatim}
\noindent{\bf Arguments:}
\noindent {\bf Return Type:}
{\tt
-float
+string
}
\vspace{0.3cm}
\vspace{0.3cm}
\vspace{0.3cm}
-\subsubsection{RPC name:~create}
+\subsubsection{RPC name:~get\_flags}
{\bf Overview:}
-Create a new host\_cpu instance, and return its handle.
+Get the flags field of the given host\_cpu.
\noindent {\bf Signature:}
-\begin{verbatim} (host_cpu ref) create (session_id s, host_cpu record args)\end{verbatim}
+\begin{verbatim} string get_flags (session_id s, host_cpu ref self)\end{verbatim}
\noindent{\bf Arguments:}
\begin{tabular}{|c|c|p{7cm}|}
\hline
{\bf type} & {\bf name} & {\bf description} \\ \hline
-{\tt host\_cpu record } & args & All constructor arguments \\ \hline
+{\tt host\_cpu ref } & self & reference to the object \\ \hline
\end{tabular}
\noindent {\bf Return Type:}
{\tt
-host\_cpu ref
+string
}
-reference to the newly created object
+value of the field
\vspace{0.3cm}
\vspace{0.3cm}
\vspace{0.3cm}
-\subsubsection{RPC name:~destroy}
+\subsubsection{RPC name:~get\_utilisation}
{\bf Overview:}
-Destroy the specified host\_cpu instance.
+Get the utilisation field of the given host\_cpu.
\noindent {\bf Signature:}
-\begin{verbatim} void destroy (session_id s, host_cpu ref self)\end{verbatim}
+\begin{verbatim} float get_utilisation (session_id s, host_cpu ref self)\end{verbatim}
\noindent{\bf Arguments:}
\noindent {\bf Return Type:}
{\tt
-void
+float
}
-
+value of the field
\vspace{0.3cm}
\vspace{0.3cm}
\vspace{0.3cm}
/*
- * Copyright (c) 2006, XenSource Inc.
+ * Copyright (c) 2006-2007, XenSource Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/*
- * The host_cpu class.
- *
+ * The host_cpu class.
+ *
* A physical CPU.
*/
char *vendor;
int64_t speed;
char *modelname;
+ char *stepping;
+ char *flags;
double utilisation;
} xen_host_cpu_record;
xen_host_cpu_get_by_uuid(xen_session *session, xen_host_cpu *result, char *uuid);
-/**
- * Create a new host_cpu instance, and return its handle.
- */
-extern bool
-xen_host_cpu_create(xen_session *session, xen_host_cpu *result, xen_host_cpu_record *record);
-
-
-/**
- * Destroy the specified host_cpu instance.
- */
-extern bool
-xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu);
-
-
/**
* Get the uuid field of the given host_cpu.
*/
xen_host_cpu_get_modelname(xen_session *session, char **result, xen_host_cpu host_cpu);
+/**
+ * Get the stepping field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_stepping(xen_session *session, char **result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the flags field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_flags(xen_session *session, char **result, xen_host_cpu host_cpu);
+
+
/**
* Get the utilisation field of the given host_cpu.
*/
/*
- * Copyright (c) 2006, XenSource Inc.
+ * Copyright (c) 2006-2007, XenSource Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
{ .key = "modelname",
.type = &abstract_type_string,
.offset = offsetof(xen_host_cpu_record, modelname) },
+ { .key = "stepping",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_host_cpu_record, stepping) },
+ { .key = "flags",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_host_cpu_record, flags) },
{ .key = "utilisation",
.type = &abstract_type_float,
.offset = offsetof(xen_host_cpu_record, utilisation) }
xen_host_record_opt_free(record->host);
free(record->vendor);
free(record->modelname);
+ free(record->stepping);
+ free(record->flags);
free(record);
}
bool
-xen_host_cpu_create(xen_session *session, xen_host_cpu *result, xen_host_cpu_record *record)
+xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
- { .type = &xen_host_cpu_record_abstract_type_,
- .u.struct_val = record }
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
};
abstract_type result_type = abstract_type_string;
*result = NULL;
- XEN_CALL_("host_cpu.create");
+ XEN_CALL_("host_cpu.get_host");
return session->ok;
}
bool
-xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu)
+xen_host_cpu_get_number(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
.u.string_val = host_cpu }
};
- xen_call_(session, "host_cpu.destroy", param_values, 1, NULL, NULL);
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("host_cpu.get_number");
return session->ok;
}
bool
-xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu host_cpu)
+xen_host_cpu_get_vendor(xen_session *session, char **result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
abstract_type result_type = abstract_type_string;
*result = NULL;
- XEN_CALL_("host_cpu.get_host");
+ XEN_CALL_("host_cpu.get_vendor");
return session->ok;
}
bool
-xen_host_cpu_get_number(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
+xen_host_cpu_get_speed(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
abstract_type result_type = abstract_type_int;
- XEN_CALL_("host_cpu.get_number");
+ XEN_CALL_("host_cpu.get_speed");
return session->ok;
}
bool
-xen_host_cpu_get_vendor(xen_session *session, char **result, xen_host_cpu host_cpu)
+xen_host_cpu_get_modelname(xen_session *session, char **result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
abstract_type result_type = abstract_type_string;
*result = NULL;
- XEN_CALL_("host_cpu.get_vendor");
+ XEN_CALL_("host_cpu.get_modelname");
return session->ok;
}
bool
-xen_host_cpu_get_speed(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
+xen_host_cpu_get_stepping(xen_session *session, char **result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
.u.string_val = host_cpu }
};
- abstract_type result_type = abstract_type_int;
+ abstract_type result_type = abstract_type_string;
- XEN_CALL_("host_cpu.get_speed");
+ *result = NULL;
+ XEN_CALL_("host_cpu.get_stepping");
return session->ok;
}
bool
-xen_host_cpu_get_modelname(xen_session *session, char **result, xen_host_cpu host_cpu)
+xen_host_cpu_get_flags(xen_session *session, char **result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
abstract_type result_type = abstract_type_string;
*result = NULL;
- XEN_CALL_("host_cpu.get_modelname");
+ XEN_CALL_("host_cpu.get_flags");
return session->ok;
}
host_cpu_attr_ro = ['host',
'number',
+ 'vendor',
+ 'speed',
+ 'modelname',
+ 'stepping',
+ 'flags',
'utilisation']
# attributes
- def host_cpu_get_host(self, session, host_cpu_ref):
+ def _host_cpu_get(self, ref, field):
+ return xen_api_success(
+ XendNode.instance().get_host_cpu_field(ref, field))
+
+ def host_cpu_get_host(self, _, ref):
return xen_api_success(XendNode.instance().uuid)
- def host_cpu_get_utilisation(self, session, host_cpu_ref):
- util = XendNode.instance().get_host_cpu_load(host_cpu_ref)
- return xen_api_success(util)
- def host_cpu_get_number(self, session, host_cpu_ref):
- num = XendNode.instance().get_host_cpu_number(host_cpu_ref)
- return xen_api_success(num)
+ def host_cpu_get_number(self, _, ref):
+ return self._host_cpu_get(ref, 'number')
+ def host_cpu_get_vendor(self, _, ref):
+ return self._host_cpu_get(ref, 'vendor')
+ def host_cpu_get_speed(self, _, ref):
+ return self._host_cpu_get(ref, 'speed')
+ def host_cpu_get_modelname(self, _, ref):
+ return self._host_cpu_get(ref, 'modelname')
+ def host_cpu_get_stepping(self, _, ref):
+ return self._host_cpu_get(ref, 'stepping')
+ def host_cpu_get_flags(self, _, ref):
+ return self._host_cpu_get(ref, 'flags')
+ def host_cpu_get_utilisation(self, _, ref):
+ return xen_api_success(XendNode.instance().get_host_cpu_load(ref))
# object methods
- def host_cpu_destroy(self, session, host_cpu_ref):
- return xen_api_error(XEND_ERROR_UNSUPPORTED)
- def host_cpu_get_record(self, session, host_cpu_ref):
+ def host_cpu_get_record(self, _, ref):
node = XendNode.instance()
- record = {'uuid': host_cpu_ref,
- 'host': node.uuid,
- 'number': node.get_host_cpu_number(host_cpu_ref),
- 'utilisation': node.get_host_cpu_load(host_cpu_ref)}
+ record = dict([(f, node.get_host_cpu_field(ref, f))
+ for f in self.host_cpu_attr_ro
+ if f not in ['uuid', 'host', 'utilisation']])
+ record['uuid'] = ref
+ record['host'] = node.uuid
+ record['utilisation'] = node.get_host_cpu_load(ref)
return xen_api_success(record)
# class methods
for cpu_uuid, cpu in saved_cpus.items():
self.cpus[cpu_uuid] = cpu
- # verify we have enough cpus here
+ cpuinfo = parse_proc_cpuinfo()
physinfo = self.physinfo_dict()
cpu_count = physinfo['nr_cpus']
cpu_features = physinfo['hw_caps']
if cpu_count != len(self.cpus):
self.cpus = {}
for i in range(cpu_count):
- cpu_uuid = uuid.createString()
- cpu_info = {'uuid': cpu_uuid,
- 'host': self.uuid,
- 'number': i,
- 'features': cpu_features}
- self.cpus[cpu_uuid] = cpu_info
+ u = uuid.createString()
+ self.cpus[u] = {'uuid': u, 'number': i }
+
+ for u in self.cpus.keys():
+ log.error(self.cpus[u])
+ number = self.cpus[u]['number']
+ log.error(number)
+ log.error(cpuinfo)
+ self.cpus[u].update(
+ { 'host' : self.uuid,
+ 'features' : cpu_features,
+ 'speed' : int(float(cpuinfo[number]['cpu MHz'])),
+ 'vendor' : cpuinfo[number]['vendor_id'],
+ 'modelname': cpuinfo[number]['model name'],
+ 'stepping' : cpuinfo[number]['stepping'],
+ 'flags' : cpuinfo[number]['flags'],
+ })
self.pifs = {}
self.pif_metrics = {}
else:
raise XendError('Invalid CPU Reference')
- def get_host_cpu_features(self, host_cpu_ref):
+ def get_host_cpu_field(self, ref, field):
try:
- return self.cpus[host_cpu_ref]['features']
+ return self.cpus[ref][field]
except KeyError:
raise XendError('Invalid CPU Reference')
- def get_host_cpu_number(self, host_cpu_ref):
- try:
- return self.cpus[host_cpu_ref]['number']
- except KeyError:
- raise XendError('Invalid CPU Reference')
-
def get_host_cpu_load(self, host_cpu_ref):
host_cpu = self.cpus.get(host_cpu_ref)
if not host_cpu:
pif.refresh(Brctl.get_state())
+def parse_proc_cpuinfo():
+ cpuinfo = {}
+ f = file('/proc/cpuinfo', 'r')
+ try:
+ p = -1
+ d = {}
+ for line in f:
+ keyvalue = line.split(':')
+ if len(keyvalue) != 2:
+ continue
+ key = keyvalue[0].strip()
+ val = keyvalue[1].strip()
+ if key == 'processor':
+ if p != -1:
+ cpuinfo[p] = d
+ p = int(val)
+ d = {}
+ else:
+ d[key] = val
+ cpuinfo[p] = d
+ return cpuinfo
+ finally:
+ f.close()
+
+
def instance():
global inst
try: